/**************************************************************

Copyright Astrium Services GEO-Information / Spot Image
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

 ***************************************************************/
package com.spotimage.catalog.client.util;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.Dialog;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.layout.HLayout;

/**
 * Loading indicator
 */
public class LoadingDialog extends Dialog {
	
	/**
	 * Singleton.
	 */
	private static LoadingDialog ld;
	
	/**
	 * Build UI.
	 */
	private LoadingDialog() {
		setTitle(" ");
		
		setIsModal(true);  
		setShowModalMask(true);  
		setAutoCenter(true);
		setWidth(120);
		setHeight(100);
		
		HLayout layout = new HLayout(5);
		layout.setWidth100();
		layout.setPadding(15);
		layout.setOverflow(Overflow.HIDDEN);
		layout.setAlign(Alignment.CENTER);
		
		Img img = new Img(Util.getImageUrl("ajax-loader.gif"), 16, 16);
		layout.addMember(img);
		
		Label label = new Label("Searching ...");
		layout.addMember(label);
		
		addItem(layout);
	}
	
	@Override
	public void closeClick() {
		hide();
	}

	/**
	 * Display singleton instance.
	 * @param display
	 */
	public static void display(boolean display) {
		if (ld == null) {
			ld = new LoadingDialog();
		}
		if (display) 
			ld.show(); 
		else 
			ld.hide();
	}

}
